﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary1.DAO;
using ClassLibrary1.Entity;

namespace Bilyteam_Website.Admin
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        private Provices provInfo;
        private ProvicesDAO provdao;
        public WebForm3()
        {
            provdao = new ProvicesDAO();
            provInfo = new Provices();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }

        }

        private void BindData()
        {
            dtlprovices.DataSource = provdao.GetAll();
            dtlprovices.DataBind();
        }

        protected void Edit_Provice(object source, DataListCommandEventArgs e)
        {
            Label lbid = e.Item.FindControl("lbid") as Label;
            Response.Redirect("ProviceEdit.aspx?provID=" + lbid.Text);
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            Provices prov = new Provices();
            prov.ProviceID = txtproviceid.Text;
            prov.ProviceName = txtprovicename.Text;
            prov.Status = false;

            provdao.Insert(prov);

            BindData();
        }

        protected void Delete_Provice(object source, DataListCommandEventArgs e)
        {
            
            string id = dtlprovices.DataKeys[e.Item.ItemIndex].ToString();
            provdao.Delete(id);
            dtlprovices.EditItemIndex = -1;
           BindData();
            
        }
    }
}